/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JMailLoadGeneratorFrame.java
 *
 * Created on 20.11.2008, 21:19:59
 */
package jmailloadgenerator;

import com.sun.mail.smtp.SMTPSendFailedException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.*;
import java.util.Properties;
import java.util.Queue;
import java.util.ResourceBundle;
import java.util.concurrent.LinkedBlockingDeque;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;

/**
 *
 * @author uli
 */
public class JMailLoadGeneratorFrame extends javax.swing.JFrame
{

    public static final String alphanumericCharset =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; //NOI18N

    /** Creates new form JMailLoadGeneratorFrame */
    public JMailLoadGeneratorFrame()
    {
        initComponents();
        //If the config file exists, read the data from the previous session
        File configFile = new File(".jmailloadgenerator"); //NOI18N
        if (configFile.exists())
        {
            LineNumberReader lr = null;
            try
            {
                lr = new LineNumberReader(new FileReader(configFile));
                serverField.setText(lr.readLine());
                userNameField.setText(lr.readLine());
                recipientField.setText(lr.readLine());
                fromField.setText(lr.readLine());
                countSpinner.setValue(new Integer(lr.readLine()));
                subjectLengthSpinner.setValue(new Integer(lr.readLine()));
                bodyLengthSpinner.setValue(new Integer(lr.readLine()));
                lr.close();
            }
            catch (IOException ex)
            {
                Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
            catch (NumberFormatException ex)
            {/*May occur when the config file is not up to date*/

            }
            finally
            {
                try
                {
                    lr.close();
                }
                catch (IOException ex)
                {
                    Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        serverLabel = new javax.swing.JLabel();
        serverField = new javax.swing.JTextField();
        userNameLabel = new javax.swing.JLabel();
        userNameField = new javax.swing.JTextField();
        passwordLabel = new javax.swing.JLabel();
        passwordField = new javax.swing.JPasswordField();
        countLabel = new javax.swing.JLabel();
        countSpinner = new javax.swing.JSpinner();
        okButton = new javax.swing.JButton();
        recipientLabel = new javax.swing.JLabel();
        recipientField = new javax.swing.JTextField();
        fromLabel = new javax.swing.JLabel();
        fromField = new javax.swing.JTextField();
        subjectLengthLabel = new javax.swing.JLabel();
        subjectLengthSpinner = new javax.swing.JSpinner();
        mailProgressBar = new javax.swing.JProgressBar();
        messageScrollPane = new javax.swing.JScrollPane();
        messageTextArea = new javax.swing.JTextArea();
        bodyLengthSpinner = new javax.swing.JSpinner();
        bodyLengthLabel = new javax.swing.JLabel();
        debugCheckbox = new javax.swing.JCheckBox();
        progressLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(i18n.getString("JMailLoadGeneratorFrame.title")); // NOI18N
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setName("jMailLoadGeneratorMainFrame"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                mainFrameClosing(evt);
            }
        });

        serverLabel.setText(i18n.getString("JMailLoadGeneratorFrame.serverLabel.text")); // NOI18N

        serverField.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.serverField.toolTipText")); // NOI18N
        serverField.setNextFocusableComponent(userNameField);

        userNameLabel.setText(i18n.getString("JMailLoadGeneratorFrame.userNameLabel.text")); // NOI18N

        userNameField.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.userNameField.toolTipText")); // NOI18N
        userNameField.setNextFocusableComponent(passwordField);

        passwordLabel.setText(i18n.getString("JMailLoadGeneratorFrame.passwordLabel.text")); // NOI18N

        passwordField.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.passwordField.toolTipText")); // NOI18N
        passwordField.setNextFocusableComponent(countSpinner);

        countLabel.setText(i18n.getString("JMailLoadGeneratorFrame.countLabel.text")); // NOI18N

        countSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(100), Integer.valueOf(0), null, Integer.valueOf(1)));
        countSpinner.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.countSpinner.toolTipText")); // NOI18N
        countSpinner.setNextFocusableComponent(subjectLengthSpinner);

        okButton.setText(i18n.getString("JMailLoadGeneratorFrame.okButton.text")); // NOI18N
        okButton.setNextFocusableComponent(serverField);
        okButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okButtonMouseClicked(evt);
            }
        });

        recipientLabel.setText(i18n.getString("JMailLoadGeneratorFrame.recipientLabel.text")); // NOI18N

        recipientField.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.recipientField.toolTipText")); // NOI18N
        recipientField.setNextFocusableComponent(fromField);

        fromLabel.setText(i18n.getString("JMailLoadGeneratorFrame.fromLabel.text")); // NOI18N

        fromField.setText("test@test.tk"); // NOI18N
        fromField.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.fromField.toolTipText")); // NOI18N
        fromField.setNextFocusableComponent(okButton);

        subjectLengthLabel.setText(i18n.getString("JMailLoadGeneratorFrame.subjectLengthLabel.text")); // NOI18N

        subjectLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(10, 1, 100, 1));
        subjectLengthSpinner.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.subjectLengthSpinner.toolTipText")); // NOI18N
        subjectLengthSpinner.setNextFocusableComponent(bodyLengthSpinner);

        mailProgressBar.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.mailProgressBar.toolTipText")); // NOI18N
        mailProgressBar.setString("0" + i18n.getString("_mails_sent")); // NOI18N
        mailProgressBar.setStringPainted(true);

        messageTextArea.setColumns(20);
        messageTextArea.setRows(5);
        messageTextArea.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.messageTextArea.toolTipText")); // NOI18N
        messageScrollPane.setViewportView(messageTextArea);

        bodyLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(32768), Integer.valueOf(1), null, Integer.valueOf(100)));
        bodyLengthSpinner.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.bodyLengthSpinner.toolTipText")); // NOI18N
        bodyLengthSpinner.setNextFocusableComponent(recipientField);

        bodyLengthLabel.setText(i18n.getString("JMailLoadGeneratorFrame.bodyLengthLabel.text")); // NOI18N

        debugCheckbox.setText(i18n.getString("JMailLoadGeneratorFrame.debugCheckbox.text")); // NOI18N
        debugCheckbox.setToolTipText(i18n.getString("JMailLoadGeneratorFrame.debugCheckbox.toolTipText")); // NOI18N

        progressLabel.setText(i18n.getString("JMailLoadGeneratorFrame.progressLabel.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(serverLabel)
                            .addComponent(userNameLabel)
                            .addComponent(passwordLabel)
                            .addComponent(countLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(userNameField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                                .addComponent(serverField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                                .addComponent(passwordField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                            .addComponent(countSpinner)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(subjectLengthLabel)
                                            .addComponent(recipientLabel)
                                            .addComponent(fromLabel))
                                        .addGap(16, 16, 16))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(progressLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(bodyLengthLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(debugCheckbox)
                                .addGap(12, 12, 12)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(okButton, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                            .addComponent(bodyLengthSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                            .addComponent(recipientField, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(mailProgressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(fromField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                            .addComponent(subjectLengthSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(messageScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(messageScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(serverLabel)
                            .addComponent(serverField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userNameLabel)
                            .addComponent(userNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(passwordLabel)
                            .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(countLabel)
                            .addComponent(countSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(subjectLengthLabel)
                            .addComponent(subjectLengthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bodyLengthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bodyLengthLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(recipientLabel)
                            .addComponent(recipientField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fromLabel)
                            .addComponent(fromField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(mailProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(progressLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(okButton)
                            .addComponent(debugCheckbox))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_okButtonMouseClicked
    {//GEN-HEADEREND:event_okButtonMouseClicked
        /**
         * If there already is a running thread, display an error message and return
         */
        if(running)
        {
            JOptionPane.showMessageDialog(this, i18n.getString("You_cannot_run_two_sender_threads_at_once!"), i18n.getString("Already_started"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        /**
         * There is no running sender thread yet so start a new one
         */
        new Thread(new Runnable()
        {

            public void run()
            {
                running = true;
                Transport tr = null;
                try
                {
                    Properties props = System.getProperties();
                    props.put("mail.smtp.host", serverField.getText()); //NOI18N
                    props.put("mail.smtp.starttls.enable", true); //NOI18N
                    props.put("mail.smtp.user", userNameField.getText()); //NOI18N
                    props.put("mail.transport.protocol", "smtp"); //NOI18N
                    props.put("mail.smtp.auth", "true"); //NOI18N
                    /**
                     * Check whether we should enable debug mode
                     * (displays mail server communication on stdout)
                     */
                    if (debugCheckbox.isSelected())
                    {
                        props.put("mail.debug", "true"); //NOI18N
                    }
                    else
                    {
                        props.put("mail.debug", "false"); //NOI18N
                    }
                    Session session =
                            Session.getInstance(props,
                            new javax.mail.Authenticator()
                            {

                                @Override
                                protected PasswordAuthentication getPasswordAuthentication()
                                {
                                    return new PasswordAuthentication(userNameField.getText(), new String(passwordField.getPassword()));
                                }
                            });
                    //Get the count and length of rand
                    int count = getCount();
                    int subjectLength = getSubjectLength();
                    //Init the progress bar
                    mailProgressBar.setEnabled(true);
                    mailProgressBar.setMaximum(count);
                    mailProgressBar.setValue(0);
                    mailProgressBar.setString("0" + i18n.getString("_mails_sent")); //NOI18N
                    //Start a thread to fill the body queue
                    startBodyGenThread();
                    //Initialize the transport object the
                    tr = session.getTransport("smtp"); //NOI18N
                    tr.connect(serverField.getText(), userNameField.getText(), new String(passwordField.getPassword()));
                    //Maind send loop
                    for (i = 0; i < count; i++) //i is a field to get access from a runnable
                    {
                        //Create the message
                        MimeMessage message =
                                new MimeMessage(session);
                        message.setFrom(new InternetAddress(fromField.getText()));
                        message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipientField.getText()));
                        message.setSubject(getRand(subjectLength));
                        message.setText(bodyQueue.poll());
                        message.saveChanges();
                        //Send the message
                        tr.sendMessage(message, message.getAllRecipients());
                        //Update the progress bar
                        Runnable updateProgressBar = new Runnable()
                        {

                            public void run()
                            {
                                mailProgressBar.setValue(i);
                                mailProgressBar.setString(Integer.toString(i) + i18n.getString("_mails_sent"));
                            }
                        };
                        SwingUtilities.invokeLater(updateProgressBar);
                    }
                    messageTextArea.append(i18n.getString("Operation_completed_successfully!") + "\n"); //NOI18N
                }
                catch (SMTPSendFailedException ex)
                {
                    messageTextArea.append(ex.toString());
                    Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                catch (AuthenticationFailedException ex)
                {
                    messageTextArea.append(ex.toString());
                    Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                catch (MessagingException ex)
                {
                    Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                finally
                {
                    try
                    {
                        tr.close();
                    }
                    catch (MessagingException ex)
                    {
                        Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                running = false;
            }
        }).start();
    }//GEN-LAST:event_okButtonMouseClicked

    private void mainFrameClosing(java.awt.event.WindowEvent evt)//GEN-FIRST:event_mainFrameClosing
    {//GEN-HEADEREND:event_mainFrameClosing
        try
        {
            /**
             * Write the text field values (except password) to the config file

             */
            FileWriter fout = new FileWriter(".jmailloadgenerator"); //NOI18N
            fout.write(serverField.getText() + "\n"); //NOI18N
            fout.write(userNameField.getText() + "\n"); //NOI18N
            fout.write(recipientField.getText() + "\n"); //NOI18N
            fout.write(fromField.getText() + "\n"); //NOI18N
            fout.write(Integer.toString(getCount()) + "\n"); //NOI18N
            fout.write(Integer.toString(getSubjectLength()) + "\n"); //NOI18N
            fout.write(Integer.toString(getBodyLength()) + "\n"); //NOI18N
            fout.close();
        }
        catch (IOException ex)
        {
            Logger.getLogger(JMailLoadGeneratorFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

}//GEN-LAST:event_mainFrameClosing

    private String getRand(int len)
    {
        int alphanumericLen = alphanumericCharset.length();
        StringBuilder ret = new StringBuilder(len);
        for (; len >
                0; len--)
        {
            ret.append(alphanumericCharset.charAt(mt.nextInt(alphanumericLen)));
        }

        return ret.toString();
    }

    /**
     * Starts a thread that fills bodyQueue
     */
    private void startBodyGenThread()
    {
        new Thread(new Runnable()
        {

            public void run()
            {
                int count = getCount() + 1; //The last one may not be needed but avoids blocking
                final int bodyLen = getBodyLength();
                bodyQueue.clear();
                /**
                 * Each iteration a new String of size bodyLen is added to the Queue
                 */
                for (; count > 0; count--)
                {
                    bodyQueue.offer(getRand(bodyLen));
                }

            }
        }).start();
    }

    private int getCount()
    {
        SpinnerNumberModel countModel =
                (SpinnerNumberModel) countSpinner.getModel();
        return countModel.getNumber().intValue();
    }

    private int getSubjectLength()
    {
        SpinnerNumberModel subjectLengthModel =
                (SpinnerNumberModel) subjectLengthSpinner.getModel();
        return subjectLengthModel.getNumber().intValue();
    }

    private int getBodyLength()
    {
        SpinnerNumberModel bodyLengthModel =
                (SpinnerNumberModel) bodyLengthSpinner.getModel();
        return bodyLengthModel.getNumber().intValue();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {

            public void run()
            {
                new JMailLoadGeneratorFrame().setVisible(true);
            }
        });
    }
    private ResourceBundle i18n =
            ResourceBundle.getBundle("jmailloadgenerator/Bundle");
    private MersenneTwisterFast mt = new MersenneTwisterFast();
    private Queue<String> bodyQueue = new LinkedBlockingDeque<String>(); //Contains random bodies
    private int i;
    private boolean running = false; //true if a sending thread is running
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bodyLengthLabel;
    private javax.swing.JSpinner bodyLengthSpinner;
    private javax.swing.JLabel countLabel;
    private javax.swing.JSpinner countSpinner;
    private javax.swing.JCheckBox debugCheckbox;
    private javax.swing.JTextField fromField;
    private javax.swing.JLabel fromLabel;
    private javax.swing.JProgressBar mailProgressBar;
    private javax.swing.JScrollPane messageScrollPane;
    private javax.swing.JTextArea messageTextArea;
    private javax.swing.JButton okButton;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JLabel passwordLabel;
    private javax.swing.JLabel progressLabel;
    private javax.swing.JTextField recipientField;
    private javax.swing.JLabel recipientLabel;
    private javax.swing.JTextField serverField;
    private javax.swing.JLabel serverLabel;
    private javax.swing.JLabel subjectLengthLabel;
    private javax.swing.JSpinner subjectLengthSpinner;
    private javax.swing.JTextField userNameField;
    private javax.swing.JLabel userNameLabel;
    // End of variables declaration//GEN-END:variables
}
